package advance.reflection;

/**
 * 动态加载类
 * 定义一个接口，规定一些规范，实现类都要遵从这些规范，反射时好去创建实例
 * 动态加载类，在 Word 和 Excel 类不存在的情况下可以编译通过，后续新功能只需要实现接口即可
 */
public class ReflectionDemo02 {

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        System.out.println(args[0]);
        Class c = Class.forName(args[0]);
        OfficeAble o = (OfficeAble) c.newInstance();
        o.start();
    }

}


interface OfficeAble {

    void start();
}

class Word implements OfficeAble {

    @Override
    public void start() {
        System.out.println("Word start ...");
    }
}

class Excel implements OfficeAble {

    @Override
    public void start() {
        System.out.println("Excel start ...");
    }
}